import { ResponseInterceptor } from './../../../interceptor/response/response.interceptor';
import config from 'src/config/config';
import { Body, Controller, Delete, Get, Patch, Post, UseInterceptors } from '@nestjs/common';
import { GoodsCateService } from 'src/service/goods-cate/goods-cate.service';
import * as mongoose from 'mongoose';

@Controller(`${config.adminPath}/goodsCate`)
@UseInterceptors(ResponseInterceptor)
export class GoodsCateController {
    constructor(private readonly goodsCateService: GoodsCateService) {}
    @Get()
    async find() {
        return await this.goodsCateService.find();
    }
    @Post()
    async create(@Body() body) {
        const { pid } = body;
        if (pid && pid !== '0') {
            body.pid = new mongoose.Types.ObjectId(pid);
        }
        return await this.goodsCateService.create(body);
    }
    @Patch()
    async update(@Body() body) {
        const { pid } = body;
        if (pid && pid !== '0') {
            body.pid = new mongoose.Types.ObjectId(pid);
        }
        return await this.goodsCateService.update(body);
    }
    @Delete()
    async delete(@Body() body) {
        return await this.goodsCateService.delete(body);
    }
}
